<?php 
/**
 * Globals environment settings for Zend and Doctrine
 * @author	vsemaphore 
 * @version	$Id: global.php 141 2009-06-23 10:27:40Z vsemaphore $
 */


// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
    
defined('PUBLIC_PATH')
    || define('PUBLIC_PATH', realpath(dirname(__FILE__) . '/../public'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));

$library = glob(realpath(APPLICATION_PATH . '/../library').DIRECTORY_SEPARATOR. '*');   

$path = array(
    get_include_path(),
    realpath(APPLICATION_PATH. '/models'),
    realpath(APPLICATION_PATH. '/forms')
);

$path = array_merge($path, $library);
set_include_path(implode(PATH_SEPARATOR, $path));

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);

$system = new Zend_Config_Ini(APPLICATION_PATH . '/configs/system.ini', APPLICATION_ENV);
$systemArray = $system->toArray();
if(file_exists(APPLICATION_PATH . '/configs/local.ini')) {
	$local = new Zend_Config_Ini(APPLICATION_PATH . '/configs/local.ini', APPLICATION_ENV);
	$localArray = $local->toArray();
}
else {
	$localArray = array();
	$local = array();
}

foreach ($system as $key => $val) {
	Zend_Registry::set($key, $val);
}

foreach ($local as $key => $val) {
	Zend_Registry::set($key, $val);
}


$configArray = array_merge($systemArray, $localArray);

Zend_Registry::set('config', new Zend_Config($configArray));
